import '../../model/order_view_model.dart';
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'dart:io';
import '../../../../app_files.dart';
import '../action.dart';

class ConfigResultWidget extends StatelessWidget {
  final List<OrderConfigModel> items;
  final Dispatch dispatch;

  const ConfigResultWidget(this.items, this.dispatch);

  @override
  Widget build(BuildContext context) {
    Widget _buildItem(OrderConfigModel model) {
      return Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: double.infinity,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    height: 25,
                    width: 100,
                    child: Text(
                      model.configName,
                      style: TextThemeConfig.Font14WithColor66,
                    ),
                  ),
                  Expanded(
                    child: Text(
                      model.valueStr,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            (model.imageList == null || model.imageList.length == 0)
                ? Container()
                : Container(
                    margin: EdgeInsets.only(top: 8, bottom: 3),
                    height: 90,
                    child: ListView.builder(
                      itemBuilder: (BuildContext context, int index) {
                        var file = model.imageList[index];
                        return InkWell(
                          child: CustomImage(
                            file,
                            fit: BoxFit.fill,
                            width: 90,
                            height: 90,
                          ),
                          onTap: () => dispatch(
                              SafeOrderViewActionCreator.onTapResultPic(
                                  model, file)),
                        );
                      },
                      itemCount: model.imageList.length,
                      scrollDirection: Axis.horizontal,
                      itemExtent: 102,
                      padding: EdgeInsets.only(),
                    ),
                  ),
          ],
        ),
        padding: EdgeInsets.only(bottom: 10),
      );
    }

    List<Widget> _children = items.map((e) => _buildItem(e)).toList();

    return Container(
      padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 44,
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                '安检详情',
                style: TextThemeConfig.Font16BoldWithColor22,
              ),
            ),
            margin: EdgeInsets.only(bottom: 4),
          ),
          Column(
            children: _children,
          )
        ],
      ),
    );
  }
}
